package com.mef.smsplat.service;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mef.smsplat.dao.RoleInfoDao;
import com.mef.smsplat.dao.base.DataGridModel;
import com.mef.smsplat.dao.base.EntityDao;
import com.mef.smsplat.dao.base.Page;
import com.mef.smsplat.domain.RoleInfoDomain;
import com.mef.smsplat.service.base.BaseService;
import com.mef.smsplat.util.Constants;

@Service
@Transactional
public class RoleInfoService extends BaseService<RoleInfoDomain, String> {
	
	private RoleInfoDao roleInfoDao;
	
	/**增加setXXXX()方法,spring就可以通过autowire自动设置对象属性,请注意大小写*/
	public void setRoleInfoDao(RoleInfoDao roleInfoDao) {
		this.roleInfoDao = roleInfoDao;
	}

	@Override
	public EntityDao getEntityDao() {
		return this.roleInfoDao;
	}
	
	/**
	 * 分页查询
	 * @param roleName
	 * @param dgm
	 * @return
	 */
	@Transactional(readOnly=true)
	public Page<RoleInfoDomain> query(String roleName,DataGridModel dgm){
		return roleInfoDao.query(roleName, dgm);
	}
	
	@Transactional(readOnly=true)
	public List<RoleInfoDomain> queryAll(){
		return roleInfoDao.queryAll();
	}
	
	/**
	 * 查询角色名是否唯一
	 * @param name
	 * @param id
	 * @return
	 */
	@Transactional(readOnly=true)
	public boolean isUnique(String name, String id){
		boolean isUnique = roleInfoDao.queryByNameAndId(name, id);
		return isUnique;
	}
	
	/**
	 * 启用
	 */
	public void enable(String[] ids){
		//循环查询对象，并且执行操作
		for (int i = 0; i < ids.length; i++) {
			RoleInfoDomain role = roleInfoDao.getById(ids[i]);
			if(role!=null){
				role.setStatus(Constants.NORMAL);
				roleInfoDao.update(role);
			}
		}
	}
	/**
	 * 停用
	 */
	public void disable(String[] ids){
		//循环查询对象，并且执行操作
		for (int i = 0; i < ids.length; i++) {
			RoleInfoDomain role = roleInfoDao.getById(ids[i]);
			if(role!=null){
				role.setStatus(Constants.STOP);
				roleInfoDao.update(role);
			}
		}
	}

}
